package core;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.Random;

public class Utility {

	public static Random rnd = new Random();
	public static final int CLAIM = 0;

	public static int rndInt(int max) {
		if (max <= 0) return 0;
		return rnd.nextInt(max);
	}

	public static int rndInt(int min, int max) {
		return rnd.nextInt(max - min + 1) + min;
	}

	public static double rndDouble(double min, double max) {
		int int_min = (int) (min * 1000);
		int int_max = (int) (max * 1000);
		double value = (double) (rnd.nextInt(int_max - int_min + 1) + int_min) / 1000;
		// System.out.println("rnd double m/x " + int_min + " " + int_max + " -> value " + value);
		return value;
	}

	public static void drawCenteredString(Graphics g, int x, int y, String string, Font font) {
		FontMetrics metrics = g.getFontMetrics(font);
		int height = y + metrics.getAscent() / 2 - metrics.getDescent() / 2;
		int width = x - metrics.stringWidth(string) / 2;

		g.setFont(font);
		g.drawString(string, width, height);
	}

	public static boolean withinBounds(int x1, int y1, int x2, int y2, int w, int h) {
		return x1 > x2 && x1 < x2 + w && y1 > y2 && y1 < y2 + h;

	}

	public static double rndDouble() {
		return rnd.nextDouble();
	}

	public static int CalculateH(int side) {
		return (int) (Math.sin(Math.toRadians(30)) * side);
	}

	public static int CalculateR(int side) {
		return (int) (Math.cos(Math.toRadians(30)) * side);
	}

	public static boolean collisionCheck(double x1, double y1, double radius1, double x2, double y2, double radius2) {
		// compare the distance to combined radii
		double dx = x2 - x1;
		double dy = y2 - y1;
		double radii = radius1 + radius2;
		if ((dx * dx) + (dy * dy) < radii * radii) {
			return true;
		} else {
			return false;
		}
	}
}
